﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Ryder_US_Website.BUS;
using System.Collections.Generic;
using System.ComponentModel;
using Ryder_US_Website.Utils;

namespace Ryder_US_Website.Presentation.Admin
{
    public partial class User_List : System.Web.UI.Page
    {
        private String[] arr_role = new String[2] { "Quản trị", "Nhân viên" };
        private List<RUS_User> list = UserBUS.GetAll();
        RUS_User curUser = new RUS_User();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["RUS_User"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            curUser = (RUS_User)Session["RUS_User"];
            if (curUser.User_role != 0)
            {
                Response.Redirect("Home.aspx");
            }
            // Add dynamic rows.
            DataTable dt = new DataTable();
            dt.Columns.Add("#");
            dt.Columns.Add("Tên đăng nhập");
            dt.Columns.Add("Phân quyền");
            DataRow row = null;
            
            for (int i = 0; i < list.Count; i++)
            {
                row = dt.NewRow();
                row["#"] = (i + 1).ToString();
                row["Tên đăng nhập"] = "<a href=' User_Update.aspx?id="+ list[i].User_ID+"'>" + list[i].User_username + "</a>";
                row["Phân quyền"] = arr_role[list[i].User_role];
                dt.Rows.Add(row);
            }
            gvUser.DataSource = dt;
            gvUser.DataBind();
        }

        protected void gvUser_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[1].Text = Server.HtmlDecode(e.Row.Cells[1].Text);
            }
        }

        protected void gvUser_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvUser.PageIndex = e.NewPageIndex;
            gvUser.DataBind();
        }
    }
}
